package com.qianfeng.chinamobile.strategy.mq.listeners;


import com.qianfeng.chinamobile.strategy.events.UpdateFilterEvent;
import com.qianfeng.smsplatform.common.constants.RabbitMqConsants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

@Component
public class FilterChangeListener {

    private ApplicationContext context;

    @Autowired
    public void setContext(ApplicationContext context) {
        this.context = context;
    }

    /**
     * 监听过滤器发生变化的消息
     * @param message 没有任何意义,我们主要是要知道发生变化了
     */
    @StreamListener(RabbitMqConsants.TOPIC_EXECFILTERS_UPDATE)
    public void onMessage(String message) {
        //收到了过滤器发生变化的监听,我们要做的事情是重新加载一次过滤器
        context.publishEvent(new UpdateFilterEvent());
    }
}
